<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<style type="text/css">
			form.mui-input-group label {
				width: 30%;
				font-size: 14px;
			}
			
			form.mui-input-group input,
			form.mui-input-group textarea {
				width: 70%;
				font-size: 14px;
			}
			
			form.mui-input-group input#url {
				width: 100%;
			}
			
			form.mui-input-group .textarea {
				height: 90px;
			}
			
			.mui-radio input[type=radio]:checked:before {
				color: #FEB406;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-back mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">编辑小样&作品</h1>
			<a class="mui-pull-right">保存</a>
		</header>

		<!--视频标题-->
		<div class="mui-content">
			<h5 class="min-title">作品信息</h5>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>标题</label>
					<input type="text" id='title' class="mui-input-clear mui-input" placeholder="请输入标题">
				</div>
				<div class="mui-input-row">
					<label>类别</label>
					<input type="text" id="category" class="mui-input-clear mui-input" placeholder="如：民歌，(6字之内)" maxlength="6">
				</div>
				<div class="mui-input-row">
					<label>标签</label>
					<input type="text" id="tags" class="mui-input-clear mui-input" placeholder="如：快歌，慢歌，(6字之内)" maxlength="6">
				</div>
				<div class="mui-input-row textarea">
					<label>视频描述</label>
					<textarea rows="3" cols="15" id="description"></textarea>
				</div>
			</form>
			<!--视频类型-->
			<h5 class="min-title">选择作品类型</h5>
			<ul class="mui-table-view">
				<li class="mui-table-view-cell mui-radio">
					<input name="type" type="radio"><span>小样</span>
				</li>
				<li class="mui-table-view-cell mui-radio">
					<input name="type" type="radio"><span>作品</span>
				</li>
			</ul>
		</div>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script src="../js/5plus.js" type="text/javascript" charset="utf-8"></script>
		<!-- 5+辅助类js，与上传功能无关 -->
		<script src="../js/immersed.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/jquery.min.js"></script>
		<script src="../js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/user.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.plusReady(function(){
				var self =  plus.webview.currentWebview();
				document.getElementById("title").value = self.demoName; //小样名称
				document.getElementById("description").value = self.fdesc;//小样描述
				document.getElementById("tags").value = self.label; //小样标签
				document.getElementById("category").value = self.kind; //小样类型
				if(self.type.charAt(0) == '1') {
					$("input[type='radio']:first").prop("checked", true);
				} else {
					$("input[type='radio']:last").prop("checked", true);
				}
			
				mui('header').on('tap', '.mui-pull-right', function() {
					var videoInfo = {};
					$("input, textarea").blur();
					if($(".video-info").is(':hidden')) {
						mui.toast('请输入正确的视频网址');
					} else {
						var allRight = true;
						$("input,textarea").each(function() {
							if(!$(this).val()) {
								allRight = false;
							}
						})
						if(!$("input[type='radio']:checked").length) {
							allRight = false;
						} else {
							var type = $("input[type='radio']:checked").siblings('span').text();
							videoInfo.type = type == '小样' ? 11 : 21;
						}
						if(allRight) {
							videoInfo.demoName = $("#title").val();
							videoInfo.kind = $("#category").val();
							videoInfo.label = $("#tags").val();
							videoInfo.filehome = self.src;
							videoInfo.filename = self.vid;
							videoInfo.fdesc = $("#description").val().replace(new RegExp('\n', 'gm'), '');
							var postData = Common.toURL(videoInfo).substr(1, Common.toURL(videoInfo).length - 2);
							console.log(postData);
							var url = baseURL + 'artistOpus/updateArtistOpus/' + self.mypid + '.json';
							console.log(url);
							Common.ajax({
								url : url,
								type : 'POST',
								data : postData
							}, function(data) {
								console.log(JSON.stringify(data));
								if(data.code == 1) {
									mui.toast('修改成功');
									mui.fire(plus.webview.currentWebview().opener(), 'reload');
									mui.back();
								} else {
									mui.toast('发布失败，请稍后重试');
								}
							}, function(xhr) {
								mui.toast('网络异常，请稍后再试');
								console.error('failed - ' + xhr.status + ' : ' + xhr.statusText);
							})
						} else {
							mui.toast('请输入完整的视频信息后再发布');
						}
					}
				})
			})
			
		</script>

	</body>

</html>